<?php
	include_once 'Ad.php';
	//
	class AdController
	{
		public function __construct()
		{
			//
		}
		public function createDetails($ad)
		{
			$sMediaAgencyId = "SELECT Id FROM MediaAgencies WHERE Name = '$ad->getMediaAgencyName()'";
			$sCampaignId = "SELECT Id FROM Campaigns WHERE Name = '$ad->getCampaignName()'";
			$sPlacementId = "SELECT Id FROM Placements WHERE Name = '$ad->getPlacementName()'";
			//
			$s = "INSERT INTO Ads SET Name = '$ad->getName()', " . 
					"Comment = '$ad->getComment()', " . 
					"Format = '$ad->getFormat(), " . 
					"Archived = '$ad->getArchived(), " . 
					"MediaAgencyId = '$sMediaAgencyId', " . 
					"CampaignName = '$sCampaignId', " . 
					"PlacementName = '$sPlacementId', " . 
					"Enabled = '$ad->getEnabled()', " . 
					"DefaultImage = '$ad->getDefaultImage()', ". 
					"AdType = '$ad->getAdType()', ";
			$uAdId = mysql_insert_id();
			//
			$l = $ad->getClassifications();
			for($a = 0; $a < count($l); $a++)
			{
				$s = "INSERT INTO AdClassifications SET AdId = '$uAdId', " . 
						"Name = '$l[$a]->getName()'";
			}
			$l = $ad->getTags();
			for($a = 0; $a < count($l); $a++)
			{
				$s = "INSERT INTO AdTags SET AdId = '$uAdId', " . 
						"Name = '$l[$a]->getName()'";
			}
			//
			$s = "INSERT INTO AdFilters SET AdId = '$uAdId'";
		}
		public function readDetails($ad)
		{
			$s = "SELECT Id, Name, Comment, AdType, Archived" . 
					"FROM Ads WHERE Id = $ad->getId()";
		}
		public function deleteDetails($id)
		{
			//
		}
		public function updateDetails($id)
		{
			//
		}
		public function createUrls($ad)
		{
			$s = "";
		}
		public function readUrls($ad)
		{
			$s = "";
		}
		public function updateUrls($ad)
		{
			$s = "";
		}
		public function deleteUrls($ad)
		{
			$s = "";
		}
		//
		public function createBillings($ad)
		{
			$s = "";
		}
		public function readBillings($ad)
		{
			$s = "";
		}
		public function updateBillings($ad)
		{
			$s = "";
		}
		public function deleteBillings($ad)
		{
			$s = "";
		}
	}
?>